<?php

class WebGlobalRequest implements IWebRequest {
	private $Method;

	public function method() {
		return $this->Method;
	}

	protected function setMethod($newValue) {
		$this->Method = $newValue;
		return $this;
	}

	private $PathInfo;

	public function pathInfo() {
		return $this->PathInfo;
	}

	protected function setPathInfo($newValue) {
		if (!$newValue) $newValue = '/';
		$this->PathInfo = $newValue;
		return $this;
	}

	private $QueryString;

	public function queryString() {
		return $this->QueryString;
	}

	protected function setQueryString($newValue) {
		$this->QueryString = $newValue;
		return $this;
	}

	private $GETVariables;

	public function GETVariables() {
		return $this->GETVariables;
	}

	protected function setGETVariables($newValue) {
		$this->GETVariables = $newValue;
		return $this;
	}
	
	protected function addGETVariable($name, $value) {
		$this->GETVariables[$name] = $value;
	}

	private $POSTVariables;

	public function POSTVariables() {
		return $this->POSTVariables;
	}

	protected function setPOSTVariables($newValue) {
		$this->POSTVariables = $newValue;
		return $this;
	}
	
	protected function addPOSTVariable($name, $value) {
		$this->POSTVariables[$name] = $value;
	}
	
	private $Cookies;

	public function cookies() {
		return $this->Cookies;
	}

	protected function setCookies($newValue) {
		$this->Cookies = $newValue;
		return $this;
	}
	
	protected function addCookie($name, $value) {
		$this->Cookies[$name] = $value;
	}

	
	function GET($name) { return @$this->GETVariables[$name]; }
	function POST($name) { return @$this->POSTVariables[$name]; }
	function cookie($name) { return @$this->Cookies[$name]; }
	function header($name) {
		return @$_SERVER[_WebHeaderNameToSERVERKey($name)];
	}
	
	protected function __construct() {
		$clean = array();
		foreach (array('get' => $_GET, 'post' => $_POST, 'cookies' => $_COOKIE) as $what => $a) {
			$x = array();
			foreach ($a as $name => $value)
				$x[$name] = _WebCleanRequest($value);
			
			$clean[$what] = $x;
		}
		
		$this
			->setGETVariables($clean['get'])
			->setPOSTVariables($clean['post'])
			->setCookies($clean['cookies'])
			->setPathInfo((string) @$_SERVER['PATH_INFO'])
			->setQueryString((string) @$_SERVER['QUERY_STRING'])
			->setMethod(@$_SERVER['REQUEST_METHOD']? $_SERVER['REQUEST_METHOD'] : 'GET')
			->setUserName(@$_SERVER['PHP_AUTH_USER'])
			->setPassword(@$_SERVER['PHP_AUTH_PW'])
			;
	}
	
	public static function instance() {
		static $myself = null;
		if (!$myself) $myself = new WebGlobalRequest();
		return $myself;
	}
	
	private $UserName;

	public function userName() {
		return $this->UserName;
	}

	protected function setUserName($newValue) {
		$this->UserName = $newValue;
		return $this;
	}

	private $Password;

	public function password() {
		return $this->Password;
	}

	public function setPassword($newValue) {
		$this->Password = $newValue;
		return $this;
	}

	
}

?>